/**
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package us.levk.remote.drmaa.common.communication;

import java.util.Set;

import org.apache.xmlrpc.common.TypeConverter;
import org.apache.xmlrpc.common.TypeConverterFactoryImpl;


/**
 * @author levk
 *
 */
public class ExtendedTypeConverterFactory extends TypeConverterFactoryImpl {

  private static final transient TypeConverter SET_CONVERTER = new TypeConverter () {

    @Override public boolean isConvertable (Object pObject) { return pObject == null || pObject instanceof Set; }

    @Override public Object convert (Object pObject) { return pObject; }

    @Override public Object backConvert (Object result) { return result; }
  }; 

  /* (non-Javadoc)
   * @see org.apache.xmlrpc.common.TypeConverterFactoryImpl#getTypeConverter(java.lang.Class)
   */
  @SuppressWarnings ({ "rawtypes", "unchecked" }) @Override public TypeConverter getTypeConverter (Class pClass) {
    if (pClass.isAssignableFrom (Set.class)) return SET_CONVERTER;
    return super.getTypeConverter (pClass);
  }

}
